home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 4,401 to 4,500 / aol-file-protocol-4400-4401-to-4500.zip / AOLDLs / PDA-Newton Development / ND Newton LISP 0.5 / LISP.sit / LISP folder / README < prev   
Text File  |  1994-10-18  |  5KB  |  72 lines

  1. NEWTON LISP 0.5
  2.  
  3. LISP 0.5 for the Newton is an interpreter for a subset of the LISP language.  LISP is a functional list-processing language that supports recursion.  It is the language of choice for artificial intelligence applications, and later dialects such as Common LISP and Scheme are currently in active use.  The version of LISP implemented by this package is approximately a subset of any modern LISP.  
  4.  
  5. We assume here that the reader is familiar with some dialect of LISP or has found a textbook to explain the rudiments.  The LISP application has an output box, some input lines below it, and at the bottom, on the status bar, the buttons "About" and "Eval", plus two keys for typing left and right parentheses conveniently.  The Eval button evaluates an S-expression written in the input area, and prints the value in the output box.  It is also possible to define functions and constants in a Newton Notes folder and cause them to be read in.
  6.  
  7. S-expressions are, as usual, atoms or lists.  Atom names are delimited by parentheses, blanks, commas, or carriage returns.   Atom names are not case-sensitive.  Numbers will be recognized as such.  Dotted pairs are not supported.
  8.  
  9. The following functions are built in:  atom, append, car, cdr, cond, cons, csetq, equal, eval, input, list, member, null, print, quote, plus, minus, times, div, mod, lessp, zerop.  They all correspond to functions usually provided in LISP except for input.
  10.  
  11. Evaluating (input <filename>) causes input to be taken from the named Notes folder. The input function does not evaluate its argument, so if LISP S-expressions are placed in a Notes folder named "Lisp", for example, then (input lisp) will read in those S-expressions.  Only the first S-expression in each note in that folder will be read in, so you must start a new note after each definition.
  12.  
  13. Use csetq to define functions and constants.  For example, (csetq foo (quote (lambda (x) (car x)))) will define foo to be a synonym for car.  An atom can have only one value; if that value is a lambda-expression it can be used as a function.  The constants t and nil have themselves as values, and so do all numbers.
  14.  
  15. Final parentheses may be omitted from the input line and from definitions in notes.  Thus, "(csetq foo (quote (lambda (x) (car x" is enough to define foo, and "(foo (quote (a b)" is enough to evaluate it on (a b).  If more than one S-expression appears on an input line, only the first will be evaluated, and anything following it will be ignored.  Double-tap on incorrect input to bring up the keyboard.
  16.  
  17. No errors will be caught by LISP.  Mistakes like trying to take car of an atom or calling a function with too few arguments will result in a Newton error notification.
  18.  
  19. FUNCTION SUMMARY
  20.  
  21. Examples or explanations are given below for each built-in function.
  22. ("=>" means "evaluates to"):
  23.  
  24. (atom (quote x)) => t, (atom 3) => t, (atom (quote (a))) => nil.
  25. (append (quote (x)) (quote (y))) => (x y).
  26. (car (quote (a b))) => a.
  27. (cdr (quote (a b))) => (b).
  28. (cond (nil t) (t 2)) => 2.
  29. (cons t (quote (a))) => (t a).
  30. (csetq foo (quote bar)) => foo, side effect: foo => bar.
  31. (equal 1 2) => nil, (equal (quote (b)) (cdr (quote (a b)))) => t.
  32. (eval (quote (quote a))) => a.
  33. (input name) evaluates S-expressions in Notes folder "name" and its value is a list of the values of those S-expressons (in reverse order).
  34. (list t nil) => (t nil).
  35. (member t (quote (t nil))) => t, (member nil (quote (t))) => nil.
  36. (null t) => nil, (null nil) => t.
  37. (print (quote foo)) prints foo in the output box on the next available line.
  38. (quote a) => a.
  39. (plus 1 2) => 3.
  40. (minus 1) => -1.
  41. (minus 4 2) => 2.
  42. (times 2 3) => 6.
  43. (div 7 2) => 3.
  44. (mod 7 2) => 1.
  45. (lessp 2 2) => nil, (lessp 1 2) => t.
  46. (zerop 0) => t, (zerop 1) => nil.
  47.  
  48. EXAMPLES
  49.  
  50. The function "last" finds the last element of a list:
  51.  
  52. (csetq last (quote (lambda (x) (cond
  53. ((atom x) nil)
  54. ((null (cdr x)) (car x))
  55. (t (last (cdr x)))))))
  56.  
  57. (last (quote (a b)))  => b.
  58.  
  59. The function "mapcar" applies the one-argument function named as its first argument to each element of the list given as its second argument, returning the list of values.
  60.  
  61. (csetq mapcar (quote (lambda (f x) (cond
  62. ((atom x) nil)
  63. (t (cons (eval (list f (list (quote quote) (car x))))
  64.           (mapcar f (cdr x)))))))
  65.  
  66. (mapcar (quote car) (quote ((a) (b)))) => (a b).
  67.  
  68. DISTRIBUTION
  69.  
  70. LISP 0.5 is freeware and unrestricted, except that this README file must be distributed with it.  It was written by Jonathan Millen (JKMillen@aol.com) and the help of Phil Torrone (PDC Phil on AOL) is gratefully acknowledged.
  71.  
  72.